home *** CD-ROM | disk | FTP | other *** search
/ Utilities Professional 1-1500 / Utilities Professional 1-1500 (1994)(WPD)[!].iso / 12511500 / var1458.dms / var1458.adf / IDCMP / Example1.c < prev    next >
C/C++ Source or Header  |  1992-05-01  |  6KB  |  188 lines

  1. /***********************************************************/
  2. /*                                                         */
  3. /* Amiga C Encyclopedia (ACE) V3.0      Amiga C Club (ACC) */
  4. /* -------------------------------      ------------------ */
  5. /*                                                         */
  6. /* Book:    ACM Intuition               Amiga C Club       */
  7. /* Chapter: IDCMP                       Tulevagen 22       */
  8. /* File:    Example1.c                  181 41  LIDINGO    */
  9. /* Author:  Anders Bjerin               SWEDEN             */
  10. /* Date:    92-05-01                                       */
  11. /* Version: 1.10                                           */
  12. /*                                                         */
  13. /*   Copyright 1992, Anders Bjerin - Amiga C Club (ACC)    */
  14. /*                                                         */
  15. /* Registered members may use this program freely in their */
  16. /*     own commercial/noncommercial programs/articles.     */
  17. /*                                                         */
  18. /***********************************************************/
  19.  
  20. /* This example shows how to handle MOUSEBUTTONS event. */
  21.  
  22.  
  23.  
  24. #include <intuition/intuition.h>
  25.  
  26.  
  27.  
  28. struct IntuitionBase *IntuitionBase;
  29.  
  30.  
  31.  
  32. /* Declare a pointer to a Window structure: */ 
  33. struct Window *my_window;
  34.  
  35. /* Declare and initialize your NewWindow structure: */
  36. struct NewWindow my_new_window=
  37. {
  38.   50,            /* LeftEdge    x position of the window. */
  39.   25,            /* TopEdge     y positio of the window. */
  40.   320,           /* Width       320 pixels wide. */
  41.   100,           /* Height      100 lines high. */
  42.   0,             /* DetailPen   Text should be drawn with colour reg. 0 */
  43.   1,             /* BlockPen    Blocks should be drawn with colour reg. 1 */
  44.   CLOSEWINDOW|   /* IDCMPFlags  We will recieve a message when the user:  */
  45.                  /*             selects the Close window gad, or when the */
  46.   MOUSEBUTTONS,  /*             user presses/releases the mouse buttons.  */
  47.   SMART_REFRESH| /* Flags       Intuition should refresh the window. */
  48.   WINDOWCLOSE|   /*             Close Gadget. */
  49.   WINDOWDRAG|    /*             Drag gadget. */
  50.   WINDOWDEPTH|   /*             Depth arrange Gadgets. */
  51.   WINDOWSIZING|  /*             Sizing Gadget. */
  52.   ACTIVATE|      /*             The window should be Active when opened. */
  53.   
  54.   RMBTRAP,       /*             We do not want any menu operations for   */
  55.                  /*             this window. We can then recieve         */
  56.                  /*             MOUSEBUTTONS events even if the right    */
  57.                  /*             mouse button is pressed. (Such event are */
  58.                  /*             normally swollowed by Intuition.)        */
  59.  
  60.   NULL,          /* FirstGadget No gadgets connected to this window. */
  61.   NULL,          /* CheckMark   Use Intuition's default CheckMark. */
  62.   "PRESS THE BUTTONS", /* Title Title of the window. */
  63.   NULL,          /* Screen      Connected to the Workbench Screen. */
  64.   NULL,          /* BitMap      No Custom BitMap. */
  65.   100,           /* MinWidth    We will not allow the window to become */
  66.   50,            /* MinHeight   smaller than 100 x 50, and not bigger */
  67.   400,           /* MaxWidth    than 400 x 200. */
  68.   200,           /* MaxHeight */
  69.   WBENCHSCREEN   /* Type        Connected to the Workbench Screen. */
  70. };
  71.  
  72.  
  73.  
  74. main()
  75. {
  76.   /* Boolean variable used for the while loop: */
  77.   BOOL close_me;
  78.  
  79.   ULONG class; /* IDCMP flag. */
  80.  
  81.   USHORT code; /* Code. */
  82.   
  83.   /* Pointer to an IntuiMessage structure: */
  84.   struct IntuiMessage *my_message;
  85.  
  86.  
  87.  
  88.   /* Before we can use Intuition we need to open the Intuition Library: */
  89.   IntuitionBase = (struct IntuitionBase *)
  90.     OpenLibrary( "intuition.library", 0 );
  91.   
  92.   if( IntuitionBase == NULL )
  93.     exit(); /* Could NOT open the Intuition Library! */
  94.  
  95.  
  96.  
  97.   /* We will now try to open the window: */
  98.   my_window = (struct Window *) OpenWindow( &my_new_window );
  99.   
  100.   /* Have we opened the window succesfully? */
  101.   if(my_window == NULL)
  102.   {
  103.     /* Could NOT open the Window! */
  104.     
  105.     /* Close the Intuition Library since we have opened it: */
  106.     CloseLibrary( IntuitionBase );
  107.  
  108.     exit();  
  109.   }
  110.  
  111.  
  112.  
  113.   /* We have opened the window, and everything seems to be OK. */
  114.  
  115.   printf("Press the mouse buttons!\n");
  116.  
  117.  
  118.  
  119.   close_me = FALSE;
  120.  
  121.   /* Stay in the while loop until the user has selected the Close window */
  122.   /* gadget: */
  123.   while( close_me == FALSE )
  124.   {
  125.     /* Wait until we have recieved a message: */
  126.     Wait( 1 << my_window->UserPort->mp_SigBit );
  127.  
  128.     /* As long as we can collect messages successfully we stay in the */
  129.     /* while-loop: */
  130.     while(my_message = (struct IntuiMessage *) GetMsg(my_window->UserPort))
  131.     {
  132.       /* After we have successfully collected the message we can read */
  133.       /* it, and save any important values which we maybe want to check */
  134.       /* later: */
  135.       class = my_message->Class;
  136.       code  = my_message->Code;
  137.  
  138.       /* After we have read it we reply as fast as possible: */
  139.       /* REMEMBER! Do never try to read a message after you have replied! */
  140.       /* (Some other process has maybe changed it.) */
  141.       ReplyMsg( my_message );
  142.  
  143.       /* Check which IDCMP flag was sent: */
  144.       switch( class )
  145.       {
  146.         case CLOSEWINDOW:  /* The user selected the Close window gadget! */
  147.                close_me=TRUE;
  148.                break;
  149.         
  150.         case MOUSEBUTTONS: /* The user pressed/released a mouse button. */
  151.                /* We shall now check wich button, and if it was pressed */
  152.                /* or released: */
  153.                switch( code )
  154.                {
  155.                  case SELECTDOWN: /* Left button pressed. */
  156.                         printf("Left mouse button pressed.\n");
  157.                         break;
  158.                  case SELECTUP:   /* Left button releassed. */
  159.                         printf("Left mouse button released.\n");
  160.                         break;
  161.                  case MENUDOWN:   /* Right button pressed. */
  162.                         printf("Right mouse button pressed.\n");
  163.                         break;
  164.                  case MENUUP:     /* Right button released. */
  165.                         printf("Right mouse button released.\n");
  166.                         break;
  167.                }
  168.                break;
  169.       }
  170.     }
  171.   }
  172.  
  173.  
  174.  
  175.   /* Close the window: */
  176.   CloseWindow( my_window );
  177.  
  178.  
  179.  
  180.   /* Close the Intuition Library: */
  181.   CloseLibrary( IntuitionBase );
  182.   
  183.   /* THE END */
  184. }
  185.  
  186.  
  187.  
  188.